<?php

/**
 * This is the model class for table "m_student_dpayment".
 *
 * The followings are the available columns in table 'm_student_dpayment':
 * @property integer $id
 * @property integer $student_payment_id
 * @property integer $student_invoice_id
 * @property string $total_invoice
 * @property string $total_payment
 * @property string $notes
 *
 * The followings are the available model relations:
 * @property MStudentHpayment $studentPayment
 * @property MStudentHinvoice $studentInvoice
 */
class MStudentDpayment extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'm_student_dpayment';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('student_payment_id, student_invoice_id, total_payment', 'required'),
			array('student_payment_id, student_invoice_id', 'numerical', 'integerOnly'=>true),
			array('total_invoice, total_payment', 'length', 'max'=>14),
			array('notes', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, student_payment_id, student_invoice_id, total_invoice, total_payment, notes', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'studentPayment' => array(self::BELONGS_TO, 'MStudentHpayment', 'student_payment_id'),
			'studentInvoice' => array(self::BELONGS_TO, 'MStudentHinvoice', 'student_invoice_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'student_payment_id' => 'Student Payment',
			'student_invoice_id' => 'Student Invoice',
			'total_invoice' => 'Total Invoice',
			'total_payment' => 'Total Payment',
			'notes' => 'Notes',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('student_payment_id',$this->student_payment_id);
		$criteria->compare('student_invoice_id',$this->student_invoice_id);
		$criteria->compare('total_invoice',$this->total_invoice,true);
		$criteria->compare('total_payment',$this->total_payment,true);
		$criteria->compare('notes',$this->notes,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return MStudentDpayment the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
